import Vue from 'vue'
import Vuex from 'vuex'
import app from './modules/app.js'
import _ from 'lodash'
import * as util from '../common/util'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: {},
    wxInfo: {},
    serverConfig: {// 整体项目的一些设置
    },

    loginPromise: null,

    home: {
      modalLoginVisible: false,
    },
  },

  mutations: {
    modelSet: (state, payload) => {
      _.set(state, payload.path, payload.data)
    },
  },

  actions: {
    async modelSetWithServer({ commit, state }, payload){
      try {
        let response = {}
        switch (payload.path) {
          case 'list':
            response = await Promise.resolve([1, 2, 3])
            break
        }
        commit('modelSet', { path: payload.path, data: response.data })
        return response
      } catch (e) {
        return Promise.reject(e)
      }
    },
  },

  modules: {
    app,
  },
})
